/*
 * imprimir.c
 *
 *  Created on: 25/10/2011
 *      Author: utn_so
 */
#include "estructuras.h"
#include "utils.h"
#include "funcionesBasicas.h"
#include "entriesLFN.h"
#include <stdio.h>
#include <string.h>

//****************************************************************************************************


void imprimirListaClusters(PtrListaClusters lista){

        PtrListaClusters ptrAux;
        ptrAux = lista;

        if ( lista == NULL){ printf("\nNULL");}
        else{
                while (ptrAux != NULL){
                        printf("\n%x ",ptrAux->cluster);
                        ptrAux = ptrAux->clusterSgte;
                }
        }

}



void imprimirSector(uint8_t *sector){

	uint16_t numBytes= 0;

    for (uint16_t bytePorLeer = 0; bytePorLeer <= SIZE_SECTOR - 1; bytePorLeer++) {

    	printf("%x ",sector[bytePorLeer]);//%x imprime hexadecimales
        numBytes++;

        if (numBytes == 8){
        	printf("\n");
            numBytes = 0;
        }
    }
}

void imprimirFatRegion(FatRegion tabla){

        uint32_t cantBytes = 0;

        for( uint32_t entradaFAT = 0; entradaFAT < LONGITUD_TABLA_FAT; entradaFAT++){

                printf("%x ",tabla.entradasFat[entradaFAT]);
                cantBytes++;
                if (cantBytes == 32){printf("\n"); cantBytes = 0;}
        }
        return;
}

void imprimirContenidoCluster(Cluster cluster){

	for (uint32_t nroSector = 0; nroSector < SIZE_CLUSTER; nroSector++){

                for (uint16_t nroByte = 0; nroByte < SIZE_SECTOR; nroByte++){

                	printf("%x  \n",cluster.sectores[nroSector].bytes[nroByte]);
                }
	}
	return;
}

void imprimirBitMap (){

	uint32_t indice;
	for( indice = 0 ; indice < LONGITUD_TABLA_FAT; indice++){

			printf("%d \n",vectorBitMap.bitmap[indice]);

	}

}

void imprimirCacheFat(CacheFat cacheFat){

	uint8_t nroSector;

	for( nroSector = 0; nroSector < 4; nroSector++){

		imprimirSector(cacheFat.sectores[nroSector].bytes);
		printf("\n\n");

	}

}

void imprimirCache(CacheFat cache){

	uint16_t nroSector;
	uint32_t cantBytes = 0;

	for( nroSector = 0; nroSector < SIZE_BLOCK; nroSector++){

		for( uint32_t nroB = 0; nroB < SIZE_SECTOR; nroB++){
			printf("%c ",cache.sectores[nroSector].bytes[nroB]);
			cantBytes++;
			if (cantBytes == 16){printf("\n"); cantBytes = 0;}
		}
		printf("\n\n");
	}
}

void imprimirLFN(char * buffer){
		printf("-%s \n",buffer);
}

void imprimirListaLFNs(PtrListaLFN lista){

        PtrListaLFN ptrAux;
        ptrAux = lista;

        if ( lista == NULL){ printf("\nLista vacía!\n");}
        else{
                while (ptrAux != NULL){
                        imprimirLFN(ptrAux->lfn);
                        ptrAux = ptrAux->lfnSgte;
                }
        }

}


/*
void filtrarEntradas(){

	uint16_t nroSector;
	uint32_t offset;
	char *lfn;

	for (nroSector = 0; nroSector < SIZE_BLOCK; nroSector++){

		uint16_t numByte = 0;

		for( uint8_t nroEntrada = 0; nroEntrada < 16; nroEntrada++){

			uint8_t buffer[32];
			memcpy(buffer,&capaDir.sectores[nroSector].bytes[numByte],32);//capaDir se encuentra definida en estructuras.c
	        numByte = numByte + 32;

			offset = 0x0B;
			if ((buffer[offset] == 0x0F)&&(buffer[0] != 229)) {

				LFN *entryLfn = NULL;
				entryLfn = (LFN *)calloc(1,sizeof(LFN));
				castEntryToLfn(buffer,entryLfn);
				lfn = armarNombreLFN(*entryLfn);
				imprimirLFN(lfn);
				free(entryLfn);
				free(lfn);
			}
		}
	}
}*/
